﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using System.IO;
using Telerik.Web.UI;
using DevExpress.Web.ASPxUploadControl;

public partial class Pages_Upload : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["loginClient"] != null)
            {
                Customer cus = (Customer)Session["loginClient"];

                if (cus.C_Status)
                {

                }
                else
                {
                    Response.Redirect("../Pages/AccountLock.aspx");
                }
            }
            else
            {
                Response.Redirect("../Pages/Login.aspx");
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Customer cus = (Customer)Session["loginClient"];
        ImagesUI image = new ImagesUI();
        ArrayList arr=new ArrayList();
        if (RadUpload1.UploadedFiles.Count > 0)
        {
            string targetFolder = Server.MapPath("~/Upload/users/" + cus.Username);
            foreach (UploadedFile validFile in RadUpload1.UploadedFiles)
            { 
                if (!File.Exists(targetFolder + "/" + validFile.GetName()))
                {
                    arr.Add(validFile.GetName());
                    validFile.SaveAs(Path.Combine(targetFolder, validFile.GetName()), true);
                    ListBox2.Items.Add(validFile.GetName());
                }     
            }

            if (arr.Count > 0)
            {
                foreach (string item in arr)
                {
                    image.Add(item, "Upload/users/" + cus.Username + "/" + item, true,cus.Cusid);
                }
            }
        }
        
    }
}
